Skip to content

fix(xpu): add explicit device placement for Ray workers and vLLM - #527

Open
Madhustat wants to merge 2 commits into
alibaba:mainfrom
Madhustat:xpu/pr1-explicit-device-placement
Open

Madhustat wants to merge 2 commits into
alibaba:mainfrom
Madhustat:xpu/pr1-explicit-device-placement

Conversation

@Madhustat

Copy link
Copy Markdown

Title: fix(xpu): add explicit device placement for Ray workers and vLLM

Relates to #525

This PR is stacked on #526 and adds explicit XPU placement for ROLL workers and vLLM. Until #526 is merged, the GitHub diff also includes its base platform commit; the explicit-device-placement change is the final commit in this PR.

Summary

Explicitly place each ROLL worker on its assigned node-local XPU:

  • Keep all node-local XPUs visible to every Ray worker
  • Select the assigned XPU in each worker before any device work
  • Align LOCAL_RANK with the assigned XPU
  • Pass the assigned device IDs to vLLM, including for vLLM data-parallel ranks

The implementation is isolated through two platform hooks that are no-ops by default, so CUDA, ROCm, NPU, and CPU behavior is unchanged.

Motivation

ROLL isolates each worker with the platform's device-visibility variable, which for XPU is ZE_AFFINITY_MASK. With per-worker masks, each process sees a different device list than its peers, and oneCCL reports a narrow device affinity mask. In our testing, an agentic FrozenLake run with per-worker masks hung at its first trainer-to-vLLM weight broadcast.

With this change, every worker sees the same node-local XPUs and selects its assigned one with torch.xpu.set_device(), and the same workflow passes.

Changes

  • roll/platforms/platform.py: add two hooks with no-op defaults, select_assigned_devices() and
    get_vllm_device_kwargs(engine_kwargs).
  • roll/platforms/xpu.py (added by feat(xpu): add Intel XPU platform support #526):
    • Override update_env_vars_for_visible_devices() to record the assigned XPUs in ROLL_ASSIGNED_XPU_IDS and set
      LOCAL_RANK, instead of setting ZE_AFFINITY_MASK, and override get_visible_gpus() to read them back.
    • select_assigned_devices() selects the first assigned XPU with torch.xpu.set_device() and logs the placement.
    • get_vllm_device_kwargs() returns the assigned XPUs as device_ids for vLLM. This path is validated with vLLM 0.31.0+xpu, which supports device_ids on XPU; for earlier versions ROLL raises an error instead of continuing without explicit placement. With data_parallel_size > 1, vLLM's XPU worker selects its device from a slot in device_ids derived from the data-parallel rank, so the assigned XPUs are placed in that slot.
  • roll/distributed/executor/worker.py: call select_assigned_devices() at the start of Worker.__init__.
  • roll/third_party/vllm/__init__.py: pass the engine arguments to get_vllm_device_kwargs() and its result to the
    vLLM engine.

LOCAL_RANK is aligned with the assigned XPU because TRL's value-head model, used for the critic, selects its device through accelerate.PartialState, which reads LOCAL_RANK.

If ZE_AFFINITY_MASK is also set, workers raise an error, because ROLL cannot verify that all ranks see the same devices.

Validation

Hardware and software: 2 × Intel Arc Pro B70, PyTorch 2.14.0+xpu, vLLM 0.31.0+xpu, Ray 2.48.0, oneCCL 2022.0.0.

This PR with #526. Representative configurations derived from ROLL examples, reduced to two XPUs, small models, and shorter sequence lengths, with FSDP2 training, plus the repository's log-probability tests:

Workflow / test Layout Result
GRPO Separated; single XPU; colocated with 2 training ranks Pass
PPO with critic/GAE Separated; colocated with 2 training ranks Pass
GRPO, async generation Separated Pass
Agentic, FrozenLake Separated Pass
GRPO, vLLM tensor parallel across both XPUs Training on XPU 0 Pass
GRPO, MoE model, vLLM data parallel size 2 Separated; reversed device mapping; colocated Pass
DPO 2 training ranks Pass
TOPR with critic Critic on XPU 1 Pass
FSDP2 log-probability tests (tests/distributed/strategy/log_probs/) 2 training ranks Pass

Also verified:

  • With device mappings [0, 1] and [1, 0], each worker runs on its assigned XPU, and the workers use distinct physical XPUs.
  • XCCL collectives between two processes placed with select_assigned_devices() return the expected tensors.
  • With vLLM data parallel size 2, each vLLM data-parallel rank runs on the XPU ROLL assigned to it.
  • vLLM data parallel size 2 with tensor parallel size 2 passes on 4 × Intel Arc Pro B60, with each vLLM worker on its assigned XPU.
  • No narrow device affinity mask warning appeared in the validated runs.

NVIDIA, no regression. Counterpart workflows were run on 2 NVIDIA GPUs on main and on a combined branch that
includes this PR, with matching results. The platform unit tests on CPU also match main.

Scope

This PR covers explicit XPU placement for Ray workers and vLLM on a single node with multiple XPUs. These items are tracked separately:

vLLM data parallel was validated with an MoE model, because vLLM 0.31.0+xpu accepts external data parallel only for MoE models.

This PR does not change device placement on other platforms, ROLL algorithms, or model computation.

Register Intel XPU in ROLL's platform abstraction: device detection,
the XCCL communication backend, XPU device visibility for Ray workers,
and the XPU vLLM worker.

Add a supports_tensor_ipc platform flag (default True) so colocated
weight updates use the existing broadcast path when tensor IPC is
unavailable, and call the CUDA allocator and host-cache APIs only when
the PyTorch build provides them.

Document the supports_tensor_ipc flag and the Ray visible-device fallback
with one-line comments.
Keep all node-local XPUs visible to every Ray worker instead of
narrowing each worker with ZE_AFFINITY_MASK, which gives oneCCL
inconsistent device lists across processes.

Record the Ray-assigned XPUs in ROLL_ASSIGNED_XPU_IDS, align LOCAL_RANK
with the assigned XPU, select it with torch.xpu.set_device() at worker
start, and pass the assigned device IDs to vLLM. The new platform hooks
are no-ops on other platforms.

With vLLM data parallel, vLLM's XPU worker selects its device from a
node-local slot derived from the DP rank and indexes device_ids by that
slot, so for data_parallel_size > 1 order device_ids so that the slot
holds the XPUs ROLL assigned to the rank.

Document the new platform hooks with docstrings and the XPU placement
choices with one-line comments.
@Madhustat
Madhustat force-pushed the xpu/pr1-explicit-device-placement branch from 6d1af9b to e0f1a78 Compare November 27, 2026 06:03

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant